package com.example.mvvm;

import android.app.Application;

import com.example.mvvm.utils.DebugUtils;
import com.example.mvvm.view.MyRefreshFooter;
import com.example.mvvm.view.MyRefreshHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

public class MyApplication extends Application {
    private static MyApplication application;
    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        DebugUtils.enable();
    }


    public static MyApplication getApp() {
        return application;
    }

    //static 代码段可以防止内存泄露
    static {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator((context, layout) -> {
            layout.setPrimaryColorsId(R.color.colorPrimary, R.color.colorAccent);//全局设置主题颜色
            layout.setDragRate(0.4f);
            return new MyRefreshHeader(context);//.setTimeFormat(new DynamicTimeFormat("更新于 %pushActivity"));//指定为经典Header，默认是 贝塞尔雷达Header
        });
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator((context, layout) -> {
            //指定为经典Footer，默认是 BallPulseFooter
            return new MyRefreshFooter(context);
        });
    }
}
